<template>
  <el-dialog
    :close-on-click-modal="false"
    :title="isEdit ? '修改' : '新增'"
    width="800px"
    :visible.sync="visible"
  >
    <el-form
      :model="form"
      ref="form"
      :rules="rules"
      :label-position="labelPosition"
      label-width="120px"
    >
      <el-row :gutter="24">
        <el-col>
          <el-form-item label="企业名称">
            <el-input v-model="form.name" placeholder="请输入企业名称" />
          </el-form-item>
        </el-col>
        <el-col>
          <el-form-item label="经营范围">
            <el-input v-model="form.busiScope" placeholder="请输入经营范围" />
          </el-form-item>
        </el-col>
        <el-col>
          <el-form-item label="注册资金(元)" prop="regFund">
            <el-input maxlength="9" v-model.number="form.regFund" placeholder="请输入注册资金" />
          </el-form-item>
        </el-col>
        <el-col>
          <el-form-item label="本人出资比例(%)">
            <el-input maxlength="3" v-model="form.investPct" placeholder="请输入本人出资比例" />
          </el-form-item>
        </el-col>
        <el-col>
          <el-form-item label="年利润(元)" prop="yearProfit">
            <el-input :maxlength="10" v-model.number="form.yearProfit" placeholder="请输入年利润" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="handleUpdate">{{ isEdit ? '修改' : '新增' }}</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { openNotification, validateNum } from '@/utils/util'

export default {
  data() {
    return {
      isEdit: false,
      visible: false,
      form: {},
      labelPosition: 'right',
      inputWidth: {
        width: '100%'
      },
      rules: {
        regFund: validateNum,
        investPct: validateNum,
        yearProfit: validateNum
      },
      userRow: this.$route.params.userRow
    }
  },
  methods: {
    handleUpdate() {
      this.$refs.form.validate(async valid => {
        if (valid) {
          this.visible = false
          this.$emit('refresh', this.form)
        }
      })
    },
    edit(bool, row) {
      this.isEdit = bool
      console.log('row', row)
      this.visible = true
      this.form = Object.assign({}, row)
    }
  }
}
</script>
